package com.tth.learn.addproperties.java;

/**
 * 例子：创建三个窗口卖票，总票数为100张
 *
 * @Author tth
 * @Date 2022/10/31 11:20
 */
public class WindowTest {
    public static int ticket = 100;

    public static void main(String[] args) {
        Window t1 = new Window();
        t1.setName("窗口1");
        t1.start();

        Window t2 = new Window();
        t2.setName("窗口2");
        t2.start();

        Window t3 = new Window();
        t3.setName("窗口3");
        t3.start();
    }
}

class Window extends Thread {
    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(getName() + ": 卖票，票号为：" + ticket);
                ticket--;
            } else {
                break;
            }
        }
    }
}

